/* 我的审核--初审 */
<template>
  <div>
    <Card :bordered="false">
      <p slot="title">初审</p>
      <MyTrialTab :info="info" />
      <table cellspacing="0" cellpadding="0" border="1" width="100%">
        <tr>
          <th colspan="4">初审单</th>
        </tr>
        <tr>
          <td width="25%">初审工程师</td>
          <td width="25%">{{info.caudit}}</td>
          <td width="25%">初审时间</td>
          <td width="25%">
            {{this.$moment().format('YYYY-MM-DD')}}
          </td>
        </tr>
        <tr>
          <td colspan="4" style="padding:0 5px;">
            <div style="width:99%;margin:auto;height:100%;">
              <Table id="chushen" border ref="selection" style="border: none" :columns="chushenColumns" :data="info.Chushen"
                :loading="chushenLoading" @on-row-click="getIndex"></Table>
              <Row>
                <Col span="24" style="text-align: center;padding:10px">
                <Button type="primary" @click="inputAdd('Chushen')">添加</Button>
                <Button type="error" @click="inputRemove('Chushen')">删除</Button>
                </Col>
              </Row>
            </div>
          </td>
        </tr>
        <tr>
          <td>
            报告（正文、附图、附件、附表）
          </td>
          <td colspan="3">
            <Upload action="//jsonplaceholder.typicode.com/posts/">
              <Button>上传</Button>
            </Upload>
          </td>
        </tr>
      </table>
      <Row style="margin-top: 10px">
        <Col span="24" style="text-align:right;">
        <Button type="primary" @click="submit">发送意见</Button>
        </Col>
      </Row>
    </Card>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        info: {},
        chushenLoading: true,
        chushenColumns: [
          {
            align: 'center',
            title: '序号',
            type: 'index',
            width: 80,
          },
          {
            align: 'center',
            title: '分公司一审意见',
            key: 'Audit_opinion',
            render: (h, {
              row,
              index
            }) => {
              return h('Input', {
                props: {
                  type: 'text',
                  value: row.Audit_opinion
                },
                on: {
                  'on-blur': (val) => {
                    this.info.Chushen[index].Audit_opinion = val.target.value
                  }
                }
              })
            }
          }
        ],
        query: [],
      }
    },
    mounted() {
      let query = this.$route.query
      this.query = query
      this.findByProject(query.Project_id, query.Atype)
    },
    methods: {
      //点击添加意见
      inputAdd(type) {
        this.info[type].push({})
      },
      inputRemove(type) {
        this.info[type].splice(this.allIndex, 1);
        console.log(this.info[type] + ' 被删除了')
      },
      getIndex(data, index, event) {
        this.allIndex = index;
      },
      //获取当前项目
      findByProject(Project_id, Atype) {
        axios.get('/audit/findByProject', {
          params: {
            Atype,
            Project_id
          }
        }).then(res => {
          this.info = res
          this.chushenLoading = false
        })
      },
      submit() {
        let query = this.query
        let AuditReplyLists = this.info.Chushen
        for (let val of AuditReplyLists) {
          val['Audit_id'] = query.id
          val['Audit_time'] = this.$moment().format('YYYY-MM-DD HH:mm:ss')
        }
        if (Object.keys(AuditReplyLists).length <= 0) {
          this.$Modal.error({
            title: '点击添加请输入意见'
          })
        } else {
          axios.get('/audit/isAuditb', {
            params: {
              Project_id: query.Project_id,
              Btype: query.Atype,
              OK: 1
            }
          }).then(res => {
            let title = res._MESSAGE
            if (res._STATUS == 1) {
              this.$Modal.success({
                title: title + ': 请进入正在进行项目人员提交'
              })
              axios.post('/auditreply/saveOrUpdateM', {
                AuditReplyLists,
              }).then(res => {
              }).catch(err => {
                this.$Modal.error({
                  title: '发送失败'
                })
              })
            } else {
              this.$Modal.error({
                title: title + '：等待业务人员提交'
              })
            }
          })

        }
      },
    }
  }
</script>
<style lang="less">
  #chushen {
    .ivu-input {
      border: none !important;
      height: 30px;

      input {
        outline: medium;
      }
    }
  }
</style>